import {
    createRouter,
    createWebHistory
} from "vue-router";
import Home from "../views/Home.vue";

const routes = [{
    path: '/',
    redirect: '/dashboard'
}, {
    path: "/",
    name: "Home",
    component: Home,
    children: [{
        path: "/dashboard",
        name: "dashboard",
        meta: {
            title: 'path_home',
            dic: "首页",
            dic_en: "Home"
        },
        component: () => import(
            "../views/sys/Home.vue")
    }, {
        path: "/unit",
        name: "company",
        meta: {
            title: 'path_company',
            dic: "公司设置",
            dic_en: "Company"
        },
        component: () => import(
            "../views/Company.vue")
    }, {
        path: "/dep",
        name: "department",
        meta: {
            title: 'path_org',
            dic: "部门设置",
            dic_en: "Department"
        },
        component: () => import(
            "../views/Organization.vue")
    }, {
        path: "/pos",
        name: "postion",
        meta: {
            title: 'path_pos',
            dic: "职位设置",
            dic_en: "Position"
        },
        component: () => import(
            "../views/Position.vue")
    }, {
        path: "/emp",
        name: "employee",
        meta: {
            title: 'path_emp',
            dic: "员工基本信息",
            dic_en: "Employee"
        },
        component: () => import(
            "../views/Employee.vue")
    }, {
        path: "/table",
        name: "table",
        meta: {
            title: 'path_table',
            dic: "数据表信息",
            dic_en: "Table Info"
        },
        component: () => import(
            "../views/sys/TableInfo.vue")
    }, {
        path: "/acc",
        name: "account",
        meta: {
            title: 'path_acc',
            dic: "账号信息",
            dic_en: "Account"
        },
        component: () => import(
            "../views/Account.vue")
    },
    {
        path: "/menu",
        name: "menus",
        meta: {
            title: 'path_menus',
            dic: "菜单设置",
            dic_en: "Menu setting"
        },
        component: () => import(
            "../views/MenuTable.vue")
    }, {
        path: "/logs",
        name: "logs",
        meta: {
            title: 'path_logs',
            dic: "日志管理",
            dic_en: "Log management"
        },
        component: () => import(
            "../views/logs.vue")
    }, {
        path: "/operation",
        name: "operation",
        meta: {
            title: 'path_operation',
            dic: "操作管理",
            dic_en: "Operation management"
        },
        component: () => import(
            "../views/Operation.vue")
    },
    {
        path: "/permission",
        name: "permission",
        meta: {
            title: 'path_permission',
            dic: "权限管理",
            dic_en: "Permission management"
        },
        component: () => import(
            "../views/Permission.vue")
    }, {
        path: "/role",
        name: "role",
        meta: {
            title: 'path_Role',
            dic: "角色管理",
            dic_en: "Role management"
        },
        component: () => import(
            "../views/RoleInfo.vue")
    }, {
        path: "/dictionary",
        name: "dictionary",
        meta: {
            title: 'path_dictionary',
            dic: "字典管理",
            dic_en: "Dictionary management"
        },
        component: () => import(
            "../views/sys/Dictionary.vue")
    }, {
        path: "/btn",
        name: "button",
        meta: {
            title: '按钮管理'
        },
        component: () => import(
            "../views/Permission.vue")
    }, {
        path: "/i18n",
        name: "i18n",
        meta: {
            title: '国际化语言'
        },
        component: () => import(
            "../views/I18n.vue")
    }, {
        path: "/upload",
        name: "upload",
        meta: {
            title: '上传插件'
        },
        component: () => import(
            "../views/Upload.vue")
    }, {
        path: "/icon",
        name: "icon",
        meta: {
            title: 'path_icon',
            dic: "自定义图标",
            dic_en: "Custom ICONS"
        },
        component: () => import(
            "../views/Icon.vue")
    }, {
        path: '/test',
        name: 'test',
        meta: {
            title: '测试组件'
        },
        component: () => import(
            '../views/test.vue')
    }, {
        path: '/res',
        name: 'res',
        meta: {
            title: 'path_res',
            dic: "资源设置",
            dic_en: "Resources setting"
        },
        component: () => import(
            '../views/Resources.vue')
    }, {
        path: '/coo',
        name: 'coo',
        meta: {
            title: 'path_res',
            dic: "cooo",
            dic_en: "Resources setting"
        },
        component: () => import(
            '../views/co/canvs.vue')
    }, {
        path: "/testflow",
        name: "testflow",
        meta: {
            title: 'FLOW',
            dic: "FLOW",
            dic_en: "FLOW"
        },
        component: () => import(
            "../views/co/testflow.vue")
    }, {
        path: "/flowdesign",
        name: "flowdesign",
        meta: {
            title: 'path_flow',
            dic: "流程设置",
            dic_en: "Workflow Setting"
        },
        component: () => import(
            "../views/flow/FlowDesign.vue")
    }, {
        path: "/flowlist",
        name: "flowlist",
        meta: {
            title: 'path_flow_manager',
            dic: "流程管理",
            dic_en: "Process management"
        },
        component: () => import(
            "../views/flow/FlwoList.vue")
    }, {
        path: "/fields",
        name: "fields",
        meta: {
            title: 'path_field',
            dic: "字段管理",
            dic_en: "Field management"
        },
        component: () => import(
            "../views/sys/FieldsInfo.vue")
    }, {
        path: "/parameter",
        name: "parameter",
        meta: {
            title: 'path_parameter',
            dic: "常用参数",
            dic_en: "General Parameters"
        },
        component: () => import(
            "../views/sys/Parameter.vue")
    }, {
        path: "/document",
        name: "document",
        meta: {
            title: 'path_document',
            dic: "文档中心",
            dic_en: "Document center"
        },
        component: () => import(
            "../views/doc/doccenter.vue")
    }, {
        path: "/busfile",
        name: "busfile",
        meta: {
            title: 'path_businessfile',
            dic: "业务文件",
            dic_en: "Business documents"
        },
        component: () => import(
            "../views/doc/busFileView.vue")
    }, {
        path: "/formtable",
        name: "formtable",
        meta: {
            title: 'path_table',
            dic: "数据表信息",
            dic_en: "Table Info"
        },
        component: () => import(
            "../views/form/TableInfo.vue")
    }, {
        path: "/form",
        name: "form",
        meta: {
            title: 'path_form_set',
            dic: "表单设置",
            dic_en: "Form set"
        },
        component: () => import(
            "../views/form/FieldForm.vue")
    }, {
        path: "/formset",
        name: "formset",
        meta: {
            title: 'path_form_field_set',
            dic: "表单字段设置",
            dic_en: "Form Field set"
        },
        component: () => import(
            "../views/form/FieldFormSetting.vue")
    }, {
        path: "/flowquickfield",
        name: "flowquickfield",
        meta: {
            title: 'path_flow_quick_field_set',
            dic: "快捷字段设置",
            dic_en: "Shortcut field Settings"
        },
        component: () => import(
            "../views/flow/FlowQuickField.vue")
    }, {
        path: "/flowinstancefield",
        name: "flowinstancefield",
        meta: {
            title: 'path_flow_instance_field_set',
            dic: "实例字段设置",
            dic_en: "Instance Field Settings"
        },
        component: () => import(
            "../views/flow/FlowInstanceField.vue")
    }, {
        path: "/flowcenter",
        name: "flowcenter",
        meta: {
            title: 'path_flow_center',
            dic: "流程中心",
            dic_en: "Process Center"
        },
        component: () => import(
            "../views/flow/FlowCenter.vue")
    }, {
        path: "/process",
        name: "process",
        meta: {
            title: 'path_flow_process',
            dic: "流程",
            dic_en: "Process"
        },
        component: () => import(
            "../views/flow/FlowProcess.vue")
    }, {
        path: "/instance",
        name: "instance",
        meta: {
            title: 'path_flow_instance',
            dic: "流程实例",
            dic_en: "Instance"
        },
        component: () => import(
            "../views/flow/FlowInstance.vue")
    },
    ]
}, {
    path: "/login",
    name: "Login",
    meta: {
        title: '用户登录',
        dic: "用户登录",
        dic_en: "User Login"
    },
    component: () => import(
        "../views/Login.vue")
}];

const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes
});

router.beforeEach((to, from, next) => {
    document.title = localStorage.getItem("key_language") == "zh-cn" ? to.meta.dic : to.meta.dic_en;
    const role = localStorage.getItem('gloabl_token');
    if (!role && to.path !== '/login') {
        next('/login');
    } else {
        next();
    }
});

export default router;